const CracoLessPlugin = require('craco-less')
const SentryWebpackPlugin = require('@sentry/webpack-plugin')
const { RetryChunkLoadPlugin } = require('webpack-retry-chunk-load-plugin')
const theme = require('./package.json').theme; // antd 主题配置
const path = require('path');

const resolve = pathUrl => path.join(__dirname, '.', pathUrl)

const isProduction = process.env.NODE_ENV === 'development' ? false : true


module.exports = {

    babel: {
        plugins: [
            ['import', { libraryName: 'antd-mobile', style: true }],
            ['@babel/plugin-proposal-decorators', { legacy: true }]
        ]
    },
    plugins: [
        {
            plugin: CracoLessPlugin,
            // 此处根据 less-loader 版本的不同会有不同的配置，详见 less-loader 官方文档
            options: {
                lessLoaderOptions: {
                    lessOptions: {
                        modifyVars: theme,
                        javascriptEnabled: true,
                    }
                }
            }
        },
        {
            plugin: RetryChunkLoadPlugin,
            options: {
                cacheBust: `function() {
                    return Date.now();
                  }`,
                // optional value to set the maximum number of retries to load the chunk. Default is 1
                maxRetries: 5,
                // optional list of chunks to which retry script should be injected
                // if not set will add retry script to all chunks that have webpack script loading
                chunks: ['chunkName'],
                // optional code to be executed in the browser context if after all retries chunk is not loaded.
                // if not set - nothing will happen and error will be returned to the chunk loader.
                lastResortScript: "window.location.href='/500.html';"
            }
        }
    ],
    webpack: {
        alias: {
            "@": resolve("src"),
            "components": resolve("src/components"),
            "@tabbar": resolve("src/components/tabbar"),
            "@service": resolve("src/service/request.js"),
            "@router": resolve("src/router"),
            "@common": resolve("src/components/common"),
            "@store": resolve("src/store"),
            "@style": resolve("src/style"),
            "@api": resolve("src/service"),
            "@order": resolve("src/page/order"),
            "@home": resolve("src/page/home"),
            "@profile": resolve("src/page/profile"),
            "@submit": resolve("src/page/submit"),
            "@auth": resolve("src/page/Authentication"),
            "@page": resolve("src/page")

        },
        plugins: [
            // new SentryWebpackPlugin({
            //     release: 'v1.0.2',
            //     org: "hdy",
            //     project: "hdzp",
            //     apikey: 'fb3b44a77a3548e8aadb6611065b1f6ece310c9d0d14480c9bf9c546be4c2d1f',
            //     include: "./build/static/js",
            //     ignore: ["node_modules", "webpack.config.js", "*.css.map"],
            //     deleteAfterCompile: true, // 上传后删除 sourcemap 文件
            //     // ignoreFile: ""

            // })
        ]
    },

}